package com.irdstudio.efp.nls.service.impl;

import com.google.common.collect.Maps;
import com.irdstudio.basic.framework.core.threadpool.AbstractThreadTask;
import com.irdstudio.basic.framework.core.threadpool.ExecuteRtnInfo;
import com.irdstudio.basic.framework.core.util.SpringContextUtils;
import com.irdstudio.efp.nls.service.impl.loan_repay.CompensationTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2019/11/6
 * 功能描述:
 * 修改日期:2019/11/6
 * 修改描述:
 */
@Service("loanReleaseOrRepayQueueHangHandleService")
@Scope(scopeName = "prototype")
public class LoanReleaseOrRepayQueueHangHandle extends AbstractThreadTask {
	public static final String  NLSAPPLYINFOVO = "NlsApplyInfoVO-";
	public static final String  LOANREPAYDETAILVO = "LoanRepayDetailVO-";

	private Logger logger = LoggerFactory.getLogger(LoanReleaseOrRepayQueueHangHandle.class);
	private String key;
	private String body;

	// 类型映射
	public static final Map<String, String> serviceMap = Maps.newHashMap();
	static {
		serviceMap.put("NlsApplyInfoVO","loanReleaseCompensationTask");
		serviceMap.put("LoanRepayDetailVO","repayCompensationTask");
	}
	@Override
	public ExecuteRtnInfo call() throws Exception {
		this.doTask();
		return new ExecuteRtnInfo(null, null, null, null, true);
	}

	@Override
	public void doTask() {
		// 找出对应需要执行的服务
		for (String keyService : serviceMap.keySet()) {
			if (key.contains(keyService)) {
				try {
					CompensationTask updateService
							= SpringContextUtils.getBean(serviceMap.get(keyService), CompensationTask.class);
					updateService.parseTAndUpdateStatus(body);
				} catch (Exception e) {
					logger.error("【放款还款更新服务执行失败】"+e);
					e.printStackTrace();
				}
				return;
			}
		}
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}
}
